<?php

namespace app\admin\model;

use think\Model;

/**
 * 社群审核
 * @package app\admin\model
 */
class ResourceCheck extends Model
{
    /**
     * 社群审核总数
     * @param array $where
     * @return int
     */
    public static function countResourceCheck($where = [])
    {
        return self::where($where)->count();
    }

    /**
     * 审核列表
     * @param $where
     * @param $page
     * @param $pagesize
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getResourceList($where, $page, $pagesize)
    {
        $list = self::alias('r')
            ->join('resource_cate c', 'c.id = r.cids', 'left')
            ->join('location l', 'l.location_id = r.city', 'left')
            ->field('r.id,r.name,r.founder,r.province,r.city,r.area,r.id as rid,r.uid,r.desc,r.qrcode,r.logo,r.company,r.create_time,r.status,r.reject_reason,r.number,c.name as cate_name,l.name as city_name')
            ->where($where)
            ->whereIn('r.status', [0, -1])
            ->page($page, $pagesize)
            ->order(['r.create_time' => 'desc'])
            ->select();

        return $list ? $list->toArray() : [];
    }

    /**
     * 统计审核列表
     * @param $where
     * @return mixed
     */
    public static function countCheckList($where)
    {
        return self::alias('r')
            ->join('resource_cate c', 'c.id = r.cids', 'left')
            ->join('location l', 'l.location_id = r.city', 'left')
            ->where($where)
            ->whereIn('r.status', [0, -1])
            ->count();
    }

    /**
     * 单审核数据
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function findResourceCheck($where)
    {
        $info = self::where($where)->find();
        return $info ? $info->toArray() : [];
    }

    /**
     * 更新审核数据
     * @param $data
     * @param $where
     * @return ResourceCheck
     */
    public static function updateResourceCheck($data, $where)
    {
        return self::update($data, $where);
    }

}